package com.cn.jinl.controller;

import com.cn.jinl.api.IRepairReportService;
import com.cn.jinl.domain.RepairReport;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/repairReport")
public class RepairReportController {

  @Autowired
  private IRepairReportService iRepairReportService;

  //初始化页面查询列表
  @RequestMapping("/getRepairReportList/{frontToken}")
  @ResponseBody
  public JsonResponse<List<RepairReport>> getRepairReport(@PathVariable(value = "frontToken", required = true) String frontToken, @RequestBody QueryForm queryForm) throws Exception {
    JsonResponse<List<RepairReport>> response = new JsonResponse<>();
    List<RepairReport> repairReports = iRepairReportService.getRepairReport(queryForm);
    response.setResult(repairReports);
    response.setSuccess(true);
    return response;
  }

  //大屏数据
  @RequestMapping("/getRepairReportListDp")
  @ResponseBody
  public JsonResponse<List<RepairReport>> getRepairReportListDp(@RequestBody QueryForm queryForm) throws Exception {
    JsonResponse<List<RepairReport>> response = new JsonResponse<>();
    List<RepairReport> repairReports = iRepairReportService.getRepairReport(queryForm);
    response.setResult(repairReports);
    response.setSuccess(true);
    return response;
  }

  //app列表
  @RequestMapping("/getAppRepairReportList")
  @ResponseBody
  public JsonResponse<List<RepairReport>> getAppRepairReportList(@RequestBody QueryForm queryForm) throws Exception {
    JsonResponse<List<RepairReport>> response = new JsonResponse<>();
    List<RepairReport> repairReports = iRepairReportService.getRepairReport(queryForm);
    response.setResult(repairReports);
    response.setSuccess(true);
    return response;
  }
  //app进行扫码报修
  @RequestMapping("/addRepairReport")
  @ResponseBody
  public JsonResponse<String> addRepairReport(@RequestBody RepairReport repairReport) throws Exception{
    JsonResponse<String> response = new JsonResponse<>();
    String result = iRepairReportService.addRepairReport(repairReport);
    return CommonUtil.getResponseData(response,result);
  }



  //取消操作
  @RequestMapping("/cancelReport/{frontToken}")
  @ResponseBody
  public JsonResponse<String> cancelReport(@PathVariable(value = "frontToken", required = true) String frontToken,@RequestBody RepairReport repairReport) throws Exception{
    JsonResponse<String> response = new JsonResponse<>();
    String result = iRepairReportService.cancelReport(repairReport);
    return CommonUtil.getResponseData(response,result);
  }


  //更新操作（扫码受理的我来受理操作跟维修中的完工提交走的一个接口）
  @RequestMapping("/updateReport")
  @ResponseBody
  public JsonResponse<String> updateReport(@RequestBody RepairReport repairReport) throws Exception{
    JsonResponse<String> response = new JsonResponse<>();
    String result = iRepairReportService.updateReport(repairReport);
    return CommonUtil.getResponseData(response,result);
  }


  //pc端完工提交操作（扫码受理的我来受理操作跟维修中的完工提交走的一个接口）
  @RequestMapping("/updateByPcReport/{frontToken}")
  @ResponseBody
  public JsonResponse<String> updateByPcReport(@RequestBody RepairReport repairReport,@PathVariable(value = "frontToken", required = true) String frontToken) throws Exception{
    JsonResponse<String> response = new JsonResponse<>();
    String result = iRepairReportService.updateReport(repairReport);
    return CommonUtil.getResponseData(response,result);
  }

  //查看详情操作
  @RequestMapping("/getDetailById")
  @ResponseBody
  public JsonResponse<RepairReport> getDetailById(@RequestBody RepairReport repairReport) throws Exception{
    JsonResponse<RepairReport> response = new JsonResponse<>();
    RepairReport repairReports = iRepairReportService.getDetailById(repairReport);
    response.setResult(repairReports);
    response.setSuccess(true);
    return response;
  }

  //查看pc详情操作
  @RequestMapping("/getPcDetailById/{frontToken}")
  @ResponseBody
  public JsonResponse<RepairReport> getPcDetailById(@PathVariable(value = "frontToken", required = true) String frontToken,@RequestBody RepairReport repairReport) throws Exception{
    JsonResponse<RepairReport> response = new JsonResponse<>();
    RepairReport repairReports = iRepairReportService.getDetailById(repairReport);
    response.setResult(repairReports);
    response.setSuccess(true);
    return response;
  }
}
